package cn.iocoder.yudao.module.ent.mq.consumer.receive;

import cn.iocoder.yudao.module.ent.mq.message.receive.ReceiveSendMessage;
import cn.iocoder.yudao.module.ent.service.receivenumber.ReceiveNumberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 针对 {@link ReceiveSendMessage} 的消费者
 *
 * @author 芋道源码
 */
@Component
@Slf4j
public class ReceiveSendConsumer {

    @Resource
    private ReceiveNumberService receiveNumberService;

    @EventListener
    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    public void onMessage(ReceiveSendMessage message) {
        log.info("[ReceiveSendConsumer][消息内容({})]", message);
        receiveNumberService.doCreateReceiveNumber(message);
    }

}
